using System;
using System.Collections.Generic;
using System.Text;
using DTO;
using DAO;
using System.Data;

namespace BUS
{
    /// <summary> 
    ///Author: nnamthach@gmail.com 
    /// <summary>
    public class VENDORControl
    {
        #region Local Variable
        private VENDORDataAccess _VENDORDAO;
        #endregion Local Variable

        #region Method
        public VENDORControl()
        {
            _VENDORDAO = new VENDORDataAccess();
        }

        public VENDORInfo Get_VENDOR(
            String VendorCode
        , ref string sErr)
        {
            return _VENDORDAO.Get_VENDOR(
            VendorCode
            , ref sErr);
        }

        public DataTable GetAll_VENDOR(ref string sErr)
        {
            return _VENDORDAO.GetAll_VENDOR(ref sErr);
        }

        public Int32 Add_VENDOR(VENDORInfo obj, ref string sErr)
        {
            return _VENDORDAO.Add_VENDOR(obj, ref sErr);
        }

        public string Update_VENDOR(VENDORInfo obj)
        {
            return _VENDORDAO.Update_VENDOR(obj);
        }

        public string Delete_VENDOR(
            String VendorCode
        )
        {
            return _VENDORDAO.Delete_VENDOR(
            VendorCode
            );
        }
        public Boolean IsExist_VENDOR(
            String VendorCode
        )
        {
            return _VENDORDAO.IsExist_VENDOR(
            VendorCode
            );
        }

        public Boolean IsExist_VENDORName(
            String VendorName
        )
        {
            return _VENDORDAO.IsExist_VENDORName(
            VendorName
            );
        }

        public Boolean IsExist_VENDORNameCode(
            String VendorCode, String VendorName
        )
        {
            return _VENDORDAO.IsExist_VENDORNameCode(
            VendorCode, VendorName
            );
        }

        public string InsertUpdate(VENDORInfo obj)
        {
            string sErr = "";
            if (IsExist_VENDOR(
            obj.VendorCode
            ))
            {
                sErr = Update_VENDOR(obj);
            }
            else
                Add_VENDOR(obj, ref sErr);
            return sErr;
        }

        public string TransferIn(DataRow row)
        {
            VENDORInfo inf = new VENDORInfo(row);
            return InsertUpdate(inf);
        }

        /*  public string Delete_VENDOR(String arrID)
          {
              string kq = "";
              string[] arrStrID = arrID.Split(',');
              foreach (string strID in arrStrID)
              {
                  if (strID != "")
                  {
                      int ID = Convert.ToInt32(strID);
                      kq += _VENDORDAO.Delete_VENDOR(ID);
                  }
              }
              return kq;
          } */

        //public VENDORInfo Get_VENDOR1(String VendorCode, ref string sErr)
        //{
        //    return _VENDORDAO.Get_VENDOR1(VendorCode, ref sErr);
        //}

        //public DataTable GetAll_VENDOR1(ref string sErr)
        //{
        //    return _VENDORDAO.GetAll_VENDOR1(ref sErr);
        //}

        //public Int32 Add_VENDOR1(VENDORInfo obj, ref string sErr)
        //{
        //    return _VENDORDAO.Add_VENDOR1(obj, ref sErr);
        //}

        //public string Update_VENDOR1(VENDORInfo obj)
        //{
        //    return _VENDORDAO.Update_VENDOR1(obj);
        //}

        //public string Delete_VENDOR1(String VendorCode)
        //{
        //    return _VENDORDAO.Delete_VENDOR1(VendorCode);
        //}
        //public Boolean IsExist_VENDOR1(
        //    String VendorCode
        //)
        //{
        //    return _VENDORDAO.IsExist_VENDOR1(VendorCode);
        //}

        public DataTable Search(String columnName, String columnValue, String condition, ref String sErr)
        {
            return _VENDORDAO.Search(columnName, columnValue, condition, ref  sErr);
        }

        #endregion Method


        public DataTable GetAll(string busId, ref string sErr)
        {
            return GetAll_VENDOR(ref sErr);
            //if (busId == "HL") return GetAll_VENDOR(ref sErr);
            //return GetAll_VENDOR1(ref sErr);
        }

        public string Update(string busId, VENDORInfo info)
        {
            return Update_VENDOR(info);
            //if (busId == "HL") return Update_VENDOR(info);
            //return Update_VENDOR1(info);
        }

        public string Delete(string busId, string code)
        {
            return Delete_VENDOR(code);
            //if (busId == "HL") return Delete_VENDOR(code);
            //return Delete_VENDOR1(code);

        }

        public void Add(string busId, VENDORInfo info, ref string sErr)
        {
            Add_VENDOR(info, ref sErr);
            //if (busId == "HL") Add_VENDOR(info, ref sErr);
            //else Add_VENDOR1(info, ref sErr);
        }

        public bool IsExist(string busId, string code)
        {
            return IsExist_VENDOR(code);
            //if (busId == "HL") return IsExist_VENDOR(code);
            //return IsExist_VENDOR1(code);
        }

        public bool IsExist_Name(string busId, string name)
        {
            return IsExist_VENDORName(name);
            //if (busId == "HL") return IsExist_VENDORName(name);
            //return IsExist_VENDOR1Name(name);
        }

        //private bool IsExist_VENDOR1Name(string name)
        //{
        //    return _VENDORDAO.IsExist_VENDOR1Name(
        //    name
        //    );
        //}
    }
}
